package pe.gob.mintra.mype.daoimpl;

import java.util.ArrayList;
import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.log4j.Logger;


import pe.gob.mintra.mype.bean.ConceptoDatLab;
import pe.gob.mintra.mype.bean.SitbcReglab;
import pe.gob.mintra.mype.dao.ConceptoDAO;
import pe.gob.mintra.mype.factory.MyBatisConnectionFactory;

public class ConceptoDAOImp implements ConceptoDAO{
	
	private final static Logger logConceptoDAOImp = Logger.getLogger(ConceptoDAOImp.class);

	private SqlSessionFactory sqlSessionFactory;

	public ConceptoDAOImp() {
		sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory();
	}

	@Override
	public List<ConceptoDatLab> listarConceptoEmple(SitbcReglab objRegimen) {
		List<ConceptoDatLab> lstConcepto = new ArrayList<ConceptoDatLab>();
		SqlSession session = sqlSessionFactory.openSession();
		
		try{
			lstConcepto = (List<ConceptoDatLab>) session.selectList(
					"ConceptoDatLab.listarConceptoDatLabEmple", objRegimen);
		}catch(Exception ex){
			logConceptoDAOImp.error(ex.getMessage());
		}finally{
			session.close();
		}
		

		return lstConcepto;
	}
	
	@Override
	public List<ConceptoDatLab> listarConceptoObre(SitbcReglab objRegimen) {
		List<ConceptoDatLab> lstConcepto = new ArrayList<ConceptoDatLab>();
		SqlSession session = sqlSessionFactory.openSession();
		
		try{
			lstConcepto = (List<ConceptoDatLab>) session.selectList(
					"ConceptoDatLab.listarConceptoDatLabObre", objRegimen);
		}catch(Exception ex){
			logConceptoDAOImp.error(ex.getMessage());
		}finally{
			session.close();
		}
		

		return lstConcepto;
	}

	@Override
	public void insertarDetalleConceptoDatLab(ConceptoDatLab objConceptoDatLab) {
		SqlSession session = sqlSessionFactory.openSession();

		try {
			session.insert("ConceptoDatLab.insertarDetalleConceptoDatLab",objConceptoDatLab);
			session.commit();
		} 
		catch(Exception ex){
			session.rollback();
			logConceptoDAOImp.error(ex.getMessage());
		}
		finally {
			session.close();
		}
		
	}

	@Override
	public void actualizarDetalleConceptoDatLab(ConceptoDatLab objConceptoDatLab) {
		SqlSession session = sqlSessionFactory.openSession();

		try {
			session.update("ConceptoDatLab.actualizarDetalleConceptoDatLab",objConceptoDatLab);
			session.commit();
		} 
		catch(Exception ex){
			session.rollback();
			logConceptoDAOImp.error(ex.getMessage());
		}
		finally {
			session.close();
		}
		
	}

}
